<?php
require_once 'header.php';
?>
<!DOCTYPE html>
<html lang="en">
<head>

    <!-- start: Meta -->
    <meta charset="utf-8">
    <title>
        <?php echo $A_CONFIG['backstage_name']; ?>
    </title>
    <meta name="description" content="Bootstrap Metro Dashboard">
    <!-- end: Meta -->

    <!-- start: Mobile Specific -->
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- end: Mobile Specific -->

    <!-- start: CSS -->
    <link id="bootstrap-style" href="css/bootstrap.min.css" rel="stylesheet">
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <!--    <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">-->
    <link href="css/bootstrap-responsive.min.css" rel="stylesheet">
    <link id="base-style" href="css/style.css" rel="stylesheet">
    <link id="base-style-responsive" href="css/style-responsive.css" rel="stylesheet">
    <!--    <link href='http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800&subset=latin,cyrillic-ext,latin-ext'-->
    <!--          rel='stylesheet' type='text/css'>-->
    <link href="css/myAdmin.css" rel="stylesheet">

    <!-- end: CSS -->


    <!-- The HTML5 shim, for IE6-8 support of HTML5 elements -->
    <!--[if lt IE 9]>
    <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <link id="ie-style" href="css/ie.css" rel="stylesheet">
    <![endif]-->

    <!--[if IE 9]>
    <link id="ie9style" href="css/ie9.css" rel="stylesheet">
    <![endif]-->


</head>

<body>

<?php
include "header_menu.php";
?>

<div class="container-fluid-full">
    <div class="row-fluid">
        <?php
        include "side_nav_bar.php";
        ?>


        <!-- start: Content -->
        <div id="wrap">

            <div id="content" class="span10">

                <!-- start: 功能按钮模块-->
                <ul class="breadcrumb myBtnUl">

                    <li @click="popAddUser()">
                        <button class="btn btn-primary">管理员账号添加</button>
                    </li>
                    <li style="float: right;">
                        <div class="input-append" style="border: 1px #578ebe solid;margin-bottom: 0;">
                            <input style="height: 24px" id="search-text" size="16" type="text">
                            <button @click="search()" class="btn btn-primary" type="button">搜索</button>
                        </div>
                    </li>
                </ul>
                <!-- end: 功能按钮模块-->

                <!-- start: 列表 -->


                <div class="table-responsive">
                    <table class="table table-bordered table-striped bootstrap-datatable ">
                        <thead>
                        <tr>
                            <!--<th>#</th>-->
                            <th>账号</th>
                            <th>密码</th>
                            <th>人员管理权限</th>
                            <th>房间管理权限</th>
                            <th>入住管理权限</th>
                            <th>门店管理权限</th>
                            <th>系统管理权限</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody id="content-list">
                        <tr v-for="item in tableItems">
                            <!-- <td>{{item.info.id}}</td>-->
                            <td>{{item.info.username}}</td>
                            <td>{{item.info.password}}</td>

                            <td v-if="item.info.people_auth==1"><span class="label label-success">有权限</span></td>
                            <td v-else><span class="label label-important">无权限</span></td>

                            <td v-if="item.info.room_auth==1"><span class="label label-success">有权限</span></td>
                            <td v-else><span class="label label-important">无权限</span></td>

                            <td v-if="item.info.join_auth==1"><span class="label label-success">有权限</span></td>
                            <td v-else><span class="label label-important">无权限</span></td>

                            <td v-if="item.info.store_auth==1"><span class="label label-success">有权限</span></td>
                            <td v-else><span class="label label-important">无权限</span></td>
                            <td v-if="item.info.admin_auth==1"><span class="label label-success">有权限</span></td>
                            <td v-else><span class="label label-important">无权限</span></td>
                            <td class="user-info-config text-danger">
                                <a class="btn btn-info" @click="setUserInfo(item.info)">
                                    <i class="halflings-icon white edit"></i>
                                </a>
                                <a class="btn btn-danger" @click="deleteUserAuthority(item.info.id)">
                                    <i class="halflings-icon white trash"></i>
                                </a>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </div>
                <!--       stat：         页码-->
                <div style="text-align: center">

                    <div v-if="totalPage==0">
                        <div class="alert alert-block">
                            <button type="button" class="close" data-dismiss="alert">×</button>
                            <strong>暂无数据</strong>
                        </div>
                    </div>
                    <ul class="pagination pagination-lg" v-else>
                        <template v-if="nowPage==1">
                            <li class="disabled"><a>&laquo;</a></li>
                        </template>
                        <template v-else>
                            <li @click="getList(nowPage-1)"><a>&laquo;</a></li>
                        </template>
                        <template v-if="1<nowPage-3">
                            <li class="disabled"><a>...</a></li>
                        </template>
                        <li v-for="item in paginationItems" :class="{active:nowPage==item.page}">
                            <template v-if="nowPage-4<=item.page && item.page<=nowPage+4">
                                <a @click="getList(item.page)">{{item.page}}</a>
                            </template>
                        </li>
                        <template v-if="totalPage>nowPage+3">
                            <li class="disabled"><a>...</a></li>
                        </template>
                        <template v-if="nowPage==totalPage">
                            <li class="disabled"><a>&raquo;</a></li>
                        </template>
                        <template v-else>
                            <li @click="getList(nowPage+1)"><a>&raquo;</a></li>
                        </template>

                    </ul>
                </div><!--             end：   页码-->

                <!-- end: 列表 -->
            </div><!--/.fluid-container-->

            <!--添加单用户弹窗-->
            <div class="modal fade hide" id="pop-add-user" role="dialog" aria-hidden="true" data-backdrop="false">
                <div class="modal-dialog modal-md">
                    <div class="modal-content">
                        <div class="modal-header">
                            提示
                        </div>
                        <div class="modal-body">
                            <form role="form" class="form-horizontal">

                                <div class="control-group">
                                    <label for="pop-set-up-name" class="control-label">账号</label>
                                    <div class="controls">
                                        <input type="text" class="form-control" id="pop-add-user-name"
                                               placeholder="请输入名称"/>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label for="pop-set-up-phone" class="control-label">密码</label>
                                    <div class="controls">
                                        <input type="password" class="form-control" id="pop-add-user-passwd"
                                               placeholder="请输入名称"/>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label for="pop-set-up-class" class="control-label">密码确认</label>
                                    <div class="controls">
                                        <input type="password" class="form-control" id="pop-add-user-passwd2"
                                               placeholder="请输入名称"/>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label">权限分配</label>
                                    <div class="controls">
                                        <label class="checkbox inline">
                                            <input type="checkbox" id="people_auth" value="people_auth" name="check">人员管理权限
                                        </label>
                                        <label class="checkbox inline">
                                            <input type="checkbox" id="room_auth" value="room_auth" name="check">房间管理权限
                                        </label>
                                        <label class="checkbox inline">
                                            <input type="checkbox" id="join_auth" value="join_auth" name="check">入住管理权限
                                        </label>
                                        <label class="checkbox inline">
                                            <input type="checkbox" id="store_auth" value="store_auth" name="check">门店管理权限
                                        </label>
                                        <label class="checkbox inline">
                                            <input type="checkbox" id="admin_auth" value="admin_auth" name="check">系统管理权限
                                        </label>
                                    </div>
                                </div>


                            </form>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-primary" id="pop-add-simple-user-submit"
                                    @click="popAddUserSubmit()">确定
                            </button>
                            <button type="button" class="btn btn-danger" data-dismiss="modal">取消</button>
                        </div>
                    </div>
                </div>
            </div>
            <!--修改用户弹窗-->
            <div class="modal fade hide" id="pop-set-user" role="dialog" aria-hidden="true" data-backdrop="false">
                <div class="modal-dialog modal-md">
                    <div class="modal-content">
                        <div class="modal-header">
                            提示
                        </div>
                        <div class="modal-body">
                            <form role="form" class="form-horizontal">

                                <div class="control-group">
                                    <label for="pop-set-up-name" class="control-label">账号</label>
                                    <div class="controls">
                                        <input type="text" class="form-control" id="pop-set-user-name"
                                               placeholder="请输入名称" :value="setUp_user.username"/>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label for="pop-set-up-phone" class="control-label">密码</label>
                                    <div class="controls">
                                        <input type="password" class="form-control" id="pop-set-user-passwd"
                                               placeholder="请输入名称" :value="setUp_user.password"/>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label for="pop-set-up-class" class="control-label">密码确认</label>
                                    <div class="controls">
                                        <input type="password" class="form-control" id="pop-set-user-passwd2"
                                               placeholder="请输入名称" :value="setUp_user.password"/>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label">权限分配</label>
                                    <div class="controls">
                                        <label class="checkbox inline" v-if="setUp_user.people_auth==1">
                                            <input type="checkbox" id="set_people_auth" value="people_auth"
                                                   checked>人员管理权限
                                        </label>
                                        <label class="checkbox inline" v-else>
                                            <input type="checkbox" id="set_people_auth" value="people_auth"
                                            >人员管理权限
                                        </label>

                                        <label class="checkbox inline" v-if="setUp_user.room_auth==1">
                                            <input type="checkbox" id="set_room_auth" value="room_auth"
                                                   checked>房间管理权限
                                        </label>
                                        <label class="checkbox inline" v-else>
                                            <input type="checkbox" id="set_room_auth" value="room_auth">房间管理权限
                                        </label>

                                        <label class="checkbox inline" v-if="setUp_user.join_auth==1">
                                            <input type="checkbox" id="set_join_auth" value="join_auth"
                                                   checked>入住管理权限
                                        </label>
                                        <label class="checkbox inline" v-else>
                                            <input type="checkbox" id="set_join_auth" value="join_auth">入住管理权限
                                        </label>

                                        <label class="checkbox inline" v-if="setUp_user.store_auth==1">
                                            <input type="checkbox" id="set_store_auth" value="store_auth"
                                                   checked>门店管理权限
                                        </label>
                                        <label class="checkbox inline" v-else>
                                            <input type="checkbox" id="set_store_auth" value="store_auth">门店管理权限
                                        </label>


                                        <label class="checkbox inline" v-if="setUp_user.admin_auth==1">
                                            <input type="checkbox" id="set_admin_auth" value="admin_auth"
                                                   checked>系统管理权限
                                        </label>
                                        <label class="checkbox inline" v-else>
                                            <input type="checkbox" id="set_admin_auth" value="admin_auth">系统管理权限
                                        </label>
                                    </div>
                                </div>


                            </form>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-primary" id="pop-set-simple-user-submit"
                                    @click="popSetUserSubmit()">确定
                            </button>
                            <button type="button" class="btn btn-danger" data-dismiss="modal">取消</button>
                        </div>
                    </div>
                </div>
            </div>

        </div><!-- end: warp -->
        <!-- end: Content -->
    </div><!--/#content.span10-->
</div><!--/fluid-row-->


<iframe style="display: none;" name="uploadIframe">

</iframe>
<!-- start: JavaScript-->
<?php
//引入两个弹窗
include 'myTip_js.php';

?>

<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<!-- end: JavaScript-->
<script>
    <?php
    echo $token_info;
    ?>

    var theData = new Vue({
        el: "#wrap",
        data: {
            nowPage: 1,   //当前页码
            totalPage: 0,  //总页码
            paginationItems: [   //页面数组
                /*{page:{}}*/  //数据格式
            ],
            tableItems: [       //表格数组
                /*{info:{}}*/  //数据格式
            ],
            setUp_user: {},     //配置的用户
            search_btn_remark: "",    //存放用户搜索内容
            token: token,        //input file 的加密
            time: unixtime       //input file 的加密
        },
        methods: {
            getList: function (nextPage) {   //获取每个分页的数据
                var that = this;
                var search = "";
                if (that.search_btn_remark != "") {
                    search = that.search_btn_remark;
                }
                $.ajax({
                    url: 'api/admin/get_user_list.php',
                    type: 'POST',
                    data: {
                        token: token,
                        time: unixtime,
                        nextPage: nextPage,
                        search: search
                    },
                    dataType: 'JSON',
                    beforeSend: function () {
                        $("#loading-mask").show();
                    },
                    error: function () {
                        $("#loading-mask").hide();
                        MyAlert("请求超时");
                    },
                    success: function (res) {
                        $("#loading-mask").hide();
                        if (res.err == 0) {
                            console.log(res);
                            that.tableItems = res.msg;
                            that.nowPage = nextPage;
                        } else {
                            MyAlert(res.msg);
                        }
                    }
                })
            },
            getPagination: function () {    //获取分页数量
                var that = this;
                var search = "";
                if (that.search_btn_remark != "") {
                    search = that.search_btn_remark;
                }
                $.ajax({
                    url: 'api/admin/pag_info.php',
                    type: 'POST',
                    data: {
                        token: token,
                        time: unixtime,
                        search: search
                    },
                    dataType: 'JSON',
                    beforeSend: function () {
                        $("#loading-mask").show();
                    },
                    error: function () {
                        $("#loading-mask").hide();
                        MyAlert("分页请求超时");
                    },
                    success: function (res) {
                        $("#loading-mask").hide();
                        if (res.err == 0) {
                            console.log(res.msg);
                            that.paginationItems = res.msg;
                            that.totalPage = res.total_page;
                        } else {
                            MyAlert(res.msg);
                        }
                    }
                })
            },
            deleteUserAuthority: function (index) {   //删除用户信息
                MyConfirm("确定删除?", function () {
                    $.ajax({
                        url: "api/admin/delete_admin.php",
                        type: 'POST',
                        data: {
                            token: token,
                            time: unixtime,
                            index: index
                        },
                        dataType: 'JSON',
                        beforeSend: function () {
                            $("#loading-mask").show();
                        },
                        error: function () {
                            $("#loading-mask").hide();
                            alert("请求超时");
                        },
                        success: function (res) {
                            $("#loading-mask").hide();
                            if (res.err == 0) {
                                alert(res.msg);
                                window.location.reload();
                            } else {
                                MyAlert(res.msg);
                            }
                        }
                    })
                })
            },
            search: function () {      //查询
                var regSpace = /^\s+$/;
                if ($("#search-text").val() && !regSpace.test($("#search-text").val())) {
                    this.search_btn_remark = $("#search-text").val();
                    this.getPagination();
                    this.getList(1);
                } else {
                    MyAlert("请输入搜索内容");
                }
            },
            popUploadUser: function () {    //选择添加补助金方式弹窗
                $("#pop-upload").modal();
            },
            popAddUser: function () {      //单人添加补助金弹窗
                $("#pop-add-user").modal();
            },
            popAddUserSubmit: function () {
                var regSpace = /^\s+$/;

                var name = $("#pop-add-user-name").val();
                var passwd = $("#pop-add-user-passwd").val();
                var passwd2 = $("#pop-add-user-passwd2").val();
                var auth = '';
                var s = $("input[name='check']");
                var aa = 0;
                s.each(function (i) {
                    if (this.checked == true) {
                        if (aa) {
                            auth = auth + ',' + this.value;
                        } else {
                            auth = this.value;
                        }
                        aa++;
                    }
                });
                if (name != "" && !regSpace.test(name) && passwd != "" && !regSpace.test(passwd) && passwd2 != "" && !regSpace.test(passwd2)) {
                    if (passwd == passwd2) {
                        $.ajax({
                            url: 'api/admin/add_admin.php',
                            type: 'POST',
                            data: {
                                token: token,
                                time: unixtime,
                                username: name,
                                passwd: passwd,
                                auth: auth
                            },
                            dataType: 'JSON',
                            beforeSend: function () {
                                $("#loading-mask").show();
                            },
                            error: function () {
                                $("#loading-mask").hide();
                            },
                            success: function (res) {
                                $("#loading-mask").hide();
                                console.log(res);
                                if (res.err == 0) {
                                    alert(res.msg);
                                    window.location.reload();
                                } else {
                                    MyAlert(res.msg);
                                }
                            }
                        })

                    } else {
                        MyAlert("两次输入的密码不一致");
                    }
                } else {
                    MyAlert("请填写完整");
                }
            },
            popExcelAddUserAuthority: function () {       //Excel添加补助金弹窗
                $("#pop-excel-add-user-authority").modal();
            },
            popExcelAddGrantsSubmit: function () {

            },
            aaa: function () {
                $("#loading-mask").show();
                // $("#loading").modal();
            },
            setUserInfo: function (info) {   //修改用户信息
                this.setUp_user = info;
                console.log("ok");
                $("#pop-set-user").modal();

            },
            popSetUserSubmit: function () {
                var regSpace = /^\s+$/;
                var that = this;
                var id = that.setUp_user.id;
                var username = $("#pop-set-user-name").val();
                var passwd = $("#pop-set-user-passwd").val();
                var passwd2 = $("#pop-set-user-passwd2").val();
                //var old_passwd = that.setUp_user.password;
                //var old_username = that.setUp_user.username;
                var set_people_auth = $("#set_people_auth").is(":checked");
                var set_room_auth = $("#set_room_auth").is(":checked");
                var set_join_auth = $("#set_join_auth").is(":checked");
                var set_store_auth = $("#set_store_auth").is(":checked");
                var set_admin_auth = $("#set_admin_auth").is(":checked");
                if (username != "" && !regSpace.test(username) && passwd != "" && !regSpace.test(passwd) && passwd2 != "" && !regSpace.test(passwd2)) {
                    if (passwd == passwd2) {
                        $.ajax({
                            url: 'api/admin/set_admin.php',
                            type: 'POST',
                            data: {
                                token: token,
                                time: unixtime,
                                username: username,
                                passwd: passwd,
                                set_people_auth: set_people_auth,
                                set_room_auth:set_room_auth,
                                set_join_auth:set_join_auth,
                                set_store_auth:set_store_auth,
                                set_admin_auth:set_admin_auth,
                                id:id
                            },
                            dataType: 'JSON',
                            beforeSend: function () {
                                $("#loading-mask").show();
                            },
                            error: function () {
                                $("#loading-mask").hide();
                            },
                            success: function (res) {
                                $("#loading-mask").hide();
                                console.log(res);
                                if (res.err == 0) {
                                    alert(res.msg);
                                    window.location.reload();
                                } else {
                                    MyAlert(res.msg);
                                }
                            }
                        })

                    } else {
                        MyAlert("两次输入的密码不一致");
                    }

                } else {
                    MyAlert("请填写完整");
                }


            }
        }
    });

    theData.getPagination();   //首次加载总页码
    theData.getList(theData.nowPage);  //首次加载首个分页

</script>


</body>
</html>
